package de.jmda.gen.java.impl;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import de.jmda.gen.Generator;
import de.jmda.gen.impl.AbstractCompoundGenerator;
import de.jmda.gen.java.ImportStatementGenerator;
import de.jmda.gen.java.ImportStatementsGenerator;
import de.jmda.gen.java.naming.ImportManager;

public class ManagedImportStatementsGenerator
    extends AbstractCompoundGenerator implements ImportStatementsGenerator
{
	private ImportManager importManager;

	public ManagedImportStatementsGenerator(ImportManager importManager)
  {
	  super();
	  this.importManager = importManager;
  }

	/**
	 * Returns collection of <code>Generator</code>s with the return values of the
	 * following methods in the following order:
	 * <ul>
	 *   <li>{@link #getImportStatementGenerators()}</li>
	 * </ul>
	 * 
	 * @see de.jmda.gen.CompoundGenerator#getGeneratorComponents()
	 */
	@Override //@NotNull @Valid
  public List<Generator> getGeneratorComponents()
	{
		// copy specific generators to non-specific generators and make Java happy
		List<Generator> result = new LinkedList<Generator>();
		
		result.addAll(getImportStatementGenerators());

		return result;
	}

	@Override
	public List<ImportStatementGenerator> getImportStatementGenerators()
	{
		List<ImportStatementGenerator> result =
				new ArrayList<ImportStatementGenerator>();

		result.add(
				new DefaultImportStatementGenerator(
						importManager.generateImportStatements().toString()));

		return result;
	}
}